package org.example.sence;

import com.almasb.fxgl.dsl.FXGL;
import com.almasb.fxgl.scene.SubScene;
import javafx.geometry.Pos;
import javafx.scene.control.Button;
import javafx.scene.image.ImageView;
import javafx.scene.layout.StackPane;
import javafx.scene.layout.VBox;
import javafx.scene.paint.Color;

public class ShopSence extends SubScene {

    public ShopSence() {
        StackPane root = new StackPane();
        root.setPrefSize(FXGL.getAppWidth(), FXGL.getAppHeight());
        root.setStyle("-fx-background-color: rgba(0,0,0,0.7);");

        // 商店内容
        VBox shopUI = new VBox(10);

        ImageView view = new ImageView(FXGL.image("shop.jpeg"));
        view.setFitHeight(FXGL.getAppHeight());
        view.setFitWidth(FXGL.getAppWidth());
        shopUI.getChildren().add(view);

        shopUI.getChildren().addAll(
                createBuyButton( 100)
        );

        root.getChildren().add(shopUI);
        getContentRoot().getChildren().add(root);
    }

    private Button createBuyButton( int price) {
        Button btn = new Button("下一关");
        btn.setStyle("-fx-background-color: #015a00;");
        btn.setOnAction(e -> {
            if (FXGL.geti("money") >= price) {
                FXGL.inc("money", -price);
                FXGL.getNotificationService().pushNotification("购买成功！");
            } else {
                FXGL.getNotificationService().pushNotification("金币不足");
            }
        });
        return btn;
    }

    private Button createExitButton() {
        Button btn = new Button("返回游戏");
        btn.setOnAction(e -> FXGL.getSceneService().popSubScene());
        return btn;
    }
}
